package com.cy.bigevent.Service.impl;

import com.cy.bigevent.Service.CategoryService;
import com.cy.bigevent.mapper.CategoryMapper;
import com.cy.bigevent.pojo.Category;
import com.cy.bigevent.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void add(Category category) {
        //补充属性值，传入的只有类型和名字，还需要补充创建时间和修改时间以及修改人
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        //补充id
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        category.setCreateUser(id);

        categoryMapper.add(category);
    }
}
